<script type="text/javascript">
    var bodyTag = document.getElementsByTagName("body")[0];
    bodyTag.className = bodyTag.className.replace("noJS", "hasJS");
</script>
<style>
    .customSelect{
        float: left;
    }
</style>
<div style="text-align: center;" class="gallerylist">
    <table>
        <tr>
            <td colspan="4" style="text-align: left;padding-left: 30px;">
                <span style="float: left;padding-top: 5px;">Sắp xếp&nbsp;</span>
                <select class='custom' id='vote'>
                    <option <?= Arr::get($_REQUEST, 's')=='created'?'selected':'' ?> value="created">Mới nhất</option>
                    <option <?= Arr::get($_REQUEST, 's')=='vote'?'selected':'' ?> value="vote">Nhiều nhất</option>
                </select>
                <span style="float: left;padding-top: 5px;">&nbsp;bạn chỉ được bình chọn một lần duy nhất cho mỗi bài dự </span>
            </td>
        </tr>
        <?php
        $s_user = new Model_Service_User();
        $s_vote = new Model_Service_Vote();

        if (!empty($a_submission)) {
            foreach ($a_submission as $k => $obj) {
                $en_submission = $obj->get_data();
                $en_user = $s_user->load($en_submission->getUser_id())->get_data();
                //$count_vote = $s_vote->load_all(true, null, null, array('user_id' => $en_submission->getUser_id()));
                $j = $k + 1;
                if ($j == 1) {
                    echo "<tr>";
                }
                ?>
                <td>
                    <p class="title444">
                        <?= $en_user->getFname() ?>
                    </p>
                    <p>
                        Bình chọn: <?= (int) $en_submission->getVote() ?>
                    </p>
                    <p>
                        <img class="imgview" src="<?= $url_base_media . '/media/upload/image/' . $en_submission->getImage() ?>" val='1' alt="image05">
                    </p>
                    <p>
                        <a href="<?= URL::base() ?>chia-se/hao-hao-<?= $_user['id'] ?>.html">
                            <img src="<?= $url_base_theme ?>/img/cmdvote_19.png" val='1' alt="image05">
                        </a>
                    </p>
                </td>   

                <?php
                if ($j % 4 == 0) {
                    echo "</tr>";
                }
            }
        }
        ?>
        <tr>
            <td colspan="4">
                <?= $pagination->render() ?>
            </td>
        </tr>
    </table>
</div>
<script>
    var sb = new SelectBox({
        selectbox: $("#vote"),
        height: 150,
        width: 120,
        changeCallback: function(val, event) {
            window.location = '<?= URL::base() ?>home/rate/gallery?s='+val;
        },
    });
</script>